package com.trz.cqrs.es.exception;

import com.trz.cqrs.es.message.Message;
import lombok.Getter;


import static java.util.Objects.nonNull;
import static org.springframework.util.ObjectUtils.getDisplayString;
import static org.springframework.util.StringUtils.hasText;

@Getter
public final class InterruptedException extends CQRSException {

    private final Message interruptedMessage;

    public InterruptedException() {
        this(null, null);
    }

    public InterruptedException(String message) {
        this(message, null);
    }

    public InterruptedException(Message interruptedMessage) {
        this(null, interruptedMessage);
    }

    private InterruptedException(String message, Message interruptedMessage) {
        super(hasText(message) ? message : nonNull(interruptedMessage) ? getDisplayString(interruptedMessage) : null);
        this.interruptedMessage = interruptedMessage;
    }

}
